﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AspNetRolesData.cs" company="VDC-IT" author="Longlc">
//   AspNetRolesData class
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace VDC.VONE.DAL
{
    #region

    using System;
    using System.Data.SqlClient;
    using System.Reflection;

    using Microsoft.ApplicationBlocks.Data;

    using VDC.COMMON;
    using VDC.VONE.ENTITIES;

    #endregion

    /// <summary>
    ///     TODO: Update summary.
    /// </summary>
    public class AspNetRolesData
    {
        #region Public Methods and Operators

        /// <summary>
        /// The get asp net roles by role name.
        /// </summary>
        /// <param name="roleName">
        /// The role name.
        /// </param>
        /// <returns>
        /// The <see cref="AspNetRolesEN"/>.
        /// </returns>
        public AspNetRolesEN GetAspNetRolesByRoleName(string roleName)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                AspNetRolesEN aspNetRoles = null;
                var reader = SqlHelper.ExecuteReader(
                    SqlHelper.ConnectionString, Constants.StorepProcedure.VOneAspNetUsersInRolesByRoleName, roleName);
                while (reader.Read())
                {
                    aspNetRoles = new AspNetRolesEN();

                    if (!reader.IsDBNull(0))
                    {
                        aspNetRoles.ApplicationId = reader.GetGuid(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        aspNetRoles.RoleId = reader.GetGuid(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        aspNetRoles.RoleName = reader.GetString(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        aspNetRoles.LoweredRoleName = reader.GetString(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        aspNetRoles.Description = reader.GetString(4);
                    }
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return aspNetRoles;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        #endregion

    }
}